package io.renren.modules.back.controller;

import io.renren.common.annotation.SysLog;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.back.entity.GoodsIssueEntity;
import io.renren.modules.back.service.GoodsIssueService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * 商品问答
 *
 * @author zzh
 * @email 862583291@qq.com
 * @date 2019年02月01日 上午15:28:55
 */
@RestController
@RequestMapping("/back/goodsIssue")
public class GoodsIssueController{
  @Autowired
  private GoodsIssueService goodsIssueService;

  /**
   * 查看列表
   */
  @GetMapping("/list")
  @RequiresPermissions("goodsIssue:list")
  public R list(@RequestParam Map<String, Object> params){
    PageUtils page = goodsIssueService.queryPage(params);
    return R.ok().put("data", page);
  }

  /**
   * 查看信息
   */
  @GetMapping("/info/{id}")
  @RequiresPermissions("goodsIssue:info")
  public R info(@PathVariable("id") Long id){
    GoodsIssueEntity goodsIssueEntity = goodsIssueService.getById(id);
    return R.ok().put("data", goodsIssueEntity);
  }

  /**
   * 保存
   */
  @SysLog("保存商品问答")
  @PostMapping("/save")
  @RequiresPermissions("goodsIssue:save")
  public R save(@RequestBody GoodsIssueEntity goodsIssueEntity){
    ValidatorUtils.validateEntity(goodsIssueEntity);
    goodsIssueService.save(goodsIssueEntity);
    return R.ok();
  }

  /**
   * 修改
   */
  @SysLog("修改商品问答")
  @PostMapping("/update")
  @RequiresPermissions("goodsIssue:update")
  public R update(@RequestBody GoodsIssueEntity goodsIssueEntity){
    ValidatorUtils.validateEntity(goodsIssueEntity);
    goodsIssueService.updateById(goodsIssueEntity);
    return R.ok();
  }

  /**
   * 删除
   */
  @SysLog("删除商品问答")
  @PostMapping("/delete")
  @RequiresPermissions("goodsIssue:delete")
  public R delete(@RequestBody Long[] ids){
    goodsIssueService.removeByIds(Arrays.asList(ids));
    return R.ok();
  }
}
